The present invention relates to a translation system for translating a source program into a machine language program by using an electronic computer and, more particularly, to a translation system off the type mentioned above in which an object program common to a plurality of target computers or machines of different types can be profitably employed.
Systems for allowing programs described in high-level languages to be executed on the target computers or machines are generally classified into two systems respectively referred to as a compiler system and an interpreter system.
In the compiler system, a program described in a high-level language is translated into a machine language program oriented to a target computer, and the machine language program is executed straightforwardly by the target machine.
On the other hand, in the case of the interpreter system, a language (referred to as the intermediate language) which differs from the machine language of the target computer is prepared along with a program (referred to as the interpreter) which is adapted to interpret and execute the intermediate language program on the target computer. In other words, the high-level language program is translated into the intermediate language program which is then executed by the target computer or machine on which the interpreter program runs.
One of advantages of the compiler system over the interpreter system is seen in the greater speed of program execution which can be explained by the facts mentioned below.
(1) In the interpreter system, there are required in addition to the execution of a machine language program corresponding to an intermediate language program, allocation of the processings for the intermediate language codes as well as address calculation for operands and others. On the other hand, in the compiler system, such processing allocation and address calculation are rendered unnecessary because the machine language program can be executed directly in a straightforward manner.
(2) In the compiler system, sparing or deletion of some of the processings is possible by taking into consideration the context of program and characteristics of the target computer (i.e. program optimalization can be realized). In contrast, the interpreter can only execute the intermediate language program as it is because of its universal application to intermediate languages and thus the interpreter is not in the position to allow any processing to be spared or omitted in consideration of the program context. Besides, since the characteristics of the target computer or machine are not reflected onto the intermediate language program, it is impossible to speed up the processing by resorting to, for example, mapping of specific variables described in a high-level language to the registers incorporated in the target machine.
On the other hand, as to the usage of a program destined to be executed repeatedly, there has heretofore been adopted either one of the two methods mentioned below.
(1) According to a first method, the compiler system is adopted, wherein the machine language program obtained through the translation is preserved or stored so as to be repeatedly executed in a straightforward manner.
(2) According to the other method, the interpreter system is adopted, wherein the intermediate language program is stored for allowing repeated executions thereof by the interpreter.
When one program is to be executed repeatedly, the compiler system is adopted by an overwhelming majority of systems from the viewpoint of reducing of the time involved in execution of the program. However, the compiler system suffers from the shortcomings described below.
(1) It is necessary to provide the compiler for translating a source program into a machine language program for each type of target machine, which means that not only the quantity of compilers to be developed must necessarily increase but also the overhead involved in maintenance and extension is significantly increased because the maintenance and extension must be performed so as to be compatible with the machine types of the target computers.
(2) When one and the same program is to be executed by a plurality of target computers of different machine types, compilation (i.e. translation from a source program to a machine language program) is required for each of the machine types of the target computers, which results in the overhead for the management of the machine language programs increasing greatly.
(3) In an environment in which a plurality of computers of different machine types are connected to a network, a number of machine language programs which correspond to the number of the computers connected to the network are required for one and the same source program, which gives rise to problems with regards to the version management and disk space availability. Moreover, difficulty will be encountered in distributed execution of one and the same program.
(4) Some of the systems actually used are often operated with only the machine language program without any source program being given. In such system, exchange or switching and alterations of the component machines is difficult to realize. At present, progress in hardware technology facilitates implementation of highly sophisticated computer architecture. Nevertheless, inheritance of the machine language program resources imposes a serious limitation to alteration or modification of computer architecture.
For overcoming the disadvantages of the compiler system mentioned above, a system may be conceived in which an intermediate language program which is independent off any specific machine is employed for the purpose of preservation or storage and management of the program, wherein upon execution, the intermediate language program is translated into a machine language program of a target machine for thereby realizing high-speed processing, i.e. a system which adopts only the advantageous features of the compiler system and the interpreter system in combination. In the present state of art, however, there is known no real system which realizes the concept mentioned above.
For details of the compiler system and the interpreter system, reference may be made to "A. Aho, R. Seti and J. Ullman: Compilers. Principles, Techniques and Tools", Addison-Wesly, 1986, pp. 1-24.
In order to allow a machine-independent intermediate language program (i.e. intermediate language program which is independent of any specific target machine or computer) to be adopted as a form for preservation and management of a program to be executed repeatedly, it is required that the intermediate language program can be executed at a speed comparable to that of execution of the machine language program in the existing compiler system.
To this end, fulfillment of the requirements mentioned below will be indispensable.
(1) The intermediate language program which is in the form suited for the preservation and management as described above is not executed by the interpreter but translated into a machine language program immediately before execution.
(2) In the course of translation or conversion of the intermediate language program into the machine language program, optimization of the program is carried out by taking into consideration the characteristics of the target computer which is to execute that program.
With the present invention, it is contemplated to provide a consolidated or integrated system which can realize the requirements mentioned above, i.e. to provide a practical form of an intermediate language for storage and management of the intermediate language program together with a practical method of effectuating the translation of the intermediate language program into the machine language program upon start of execution of the program while optimizing the machine language program for the target computer.
In this conjunction, it is noted that the intermediate language code designed for the interpreter system cannot be used as the intermediate language codes for realizing what is contemplated with the present invention for the reasons described below.
(1) The intermediate language code for the interpreter system contains no information required for optimization to be effectuated upon translation into the machine language program because the intermediate language codes are not designed on the premise that it undergoes the optimization by the interpreter.
(2) The computers may be globally classified into a register machine which includes a finite number of registers and in which operations are performed primarily on the registers and a stack machine which includes operation stacks, wherein the operations or computation are performed primarily on the stack. In the current state of the art, a majority of the existing computers are implemented as the register machines. By contrast, many of the intermediate languages for the interpreter systems are designed on the presumption of operation on the stack because of the ease in designing the intermediate language codes and the interpreter. Of course, it is not absolutely impossible to convert the on-stack operation to the operation on the registers. However, great difficulty will be encountered in translating the intermediate language program for the stack machine into an efficient and effective machine language program for the register machine, when considering the fact that the values on the stack are inherently assumed to be disposable, while those on the registers should rationally be used repetitively as far as it is possible in order to make the most of the registers with high efficiency.